package structure;

public class Linked_List{
    public static void main(String[] args) {
        HeroNode hero1 = new HeroNode(1, "松江", "及时雨");
        HeroNode hero2 = new HeroNode(2, "李白", "诗仙");
        HeroNode hero3 = new HeroNode(3, "武松", "行者");

        headNode headNode = new headNode();
        headNode.add(hero1);
        headNode.add(hero2);
        headNode.add(hero3);
        System.out.println("奥对哦波2");
        headNode.list();
    }
}


class headNode{
    private HeroNode head=new HeroNode(0,"","");

    public void add(HeroNode hero){
        //找到尾节点
        HeroNode tem=head;
        while(true){
            if(tem.next==null){
                break;
            }
            tem=tem.next;
        }
       tem.next=hero;
    }

    //打印链表
    public void list(){
        HeroNode tem=head;
        if(head.next==null){
            System.out.println("链表为空");
        }
        while(true){
            if(tem.next==null){
                return;
            }
            tem= tem.next;
            System.out.println(tem);
        }
    }
}

class HeroNode{
    private int no;
    private String name;
    private String nickname;
    HeroNode next;

    public HeroNode(int no, String name, String nickname) {
        this.no = no;
        this.name = name;
        this.nickname = nickname;
        this.next = null;
    }

    @Override
    public String toString() {
        return "HeroNode{" +
                "no=" + no +
                ", name='" + name + '\'' +
                ", nickname='" + nickname + '\'' +
                '}';
    }
}
